<?php
/**
 * Created by PhpStorm.
 * User: Apache
 *  胸卡管理 
 *
 */

namespace app\api\controller\basemanage;
use app\api\controller\common\ApiBase;
use think\Db;
use think\Model;
use app\api\model\Admin as AdminModel;
use app\api\controller\common\CommonPlus;
use think\Controller; // dengh quxiao
// Controller  ApiBase （dengl）
class Yuyuemanage extends Controller
{

    protected $admin;
    protected $model = null;
    public function _initialize()
    {
        parent::_initialize();
        $this->admin = session('admin');
        //$this->model = model('CompanyPublic');
    }


    /**
     * 根据公海id获得获取
     * @return \think\response\Json|void
     *  http://dxshowxya.for.pub/index.php?s=/api/basemanage/Yuyuemanage/getList
     */

     public function getTabName($exhibition_id){
        $result=db('exhibition')->where(['id'=>$exhibition_id])->find();
        if($result){
            $tabName=$result['create_tablename'];
        }else{
            return json(['code'=>0,'msg'=>'缺少关键字段','data'=>'']);
        }
        return $tabName;
     }

    /**
     * 公海列表  0527
     * @return \think\response\Json|void
     *  comppub
     *
     */

    public function getList(){
        $page = $this->request->param('page');
        $page = max(1,intval($page));
        $pagesize =$this->request->param('pageSize')==""?20:$this->request->param('pageSize');
        $exhibition_id =$this->request->param('exhibition_id');
        $status=$this->request->param('status')==''?1:$this->request->param('status');
        if(empty($exhibition_id)){
            //return json(['code'=>0,'msg'=>'缺少关键字段','data'=>'']);
        }

        $status = input('status');
        //back字段 0代表正常 1代表退回数据 2 代表自提 3代表分配
        //status前端传入1代表 全部 2代表 不展示退回数据 3代表 只展示退回数据
        $param="";

        $keyword =input('keyword');
        if (!empty($keyword)) {
            $param.=" and company_name like '%$keyword%' ";
        }
        $sql2="select * ";
        $sql2.=" from crm_yuyue_member where 1=1 $param";
        $sql2.=" limit ".($page-1)*$pagesize.",$pagesize";
        //var_dump($sql2);die();
        $list=Db::query($sql2);
        $sql21=" select count(id) as count1 ";
        $sql21.=" from crm_yuyue_member where 1=1 $param ";
        $total1=Db::query($sql21);
        $total=$total1[0]['count1']; //st

        return json(['code'=>1,'msg'=>'success','data'=>['list'=>$list,'count'=>$total]]);
    }


    /**
     * 添加公海记录
     * @return \think\response\Json|void
     */
    public function add(){
        $com =new CommonPlus();
        $exhibition_id = $this->request->param('exhibition_id');
        $company_id = $this->request->param('company_id');
        if(empty($exhibition_id)){
           // return json(['code'=>0,'msg'=>'缺少关键字段','data'=>'']);
        }
        if(empty($company_id)){
            //return json(['code'=>0,'msg'=>'请选择企业','data'=>'']);
        }
        $data['name']=$this->request->param('name');   // 姓名
        $data['name_en']=$this->request->param('name_en');
        $data['mobile']=$this->request->param('mobile');
        $data['email']=$this->request->param('email');
        $data['country']=$this->request->param('country');
        $data['addr_post']=$this->request->param('addr_post');
        $data['company_name_en']=$this->request->param('company_name_en');
        $data['company_name']=$this->request->param('company_name');
        $data['industrys']=$this->request->param('industrys');
        $data['positions']=$this->request->param('positions');
        $data['department_cn']=$this->request->param('department_cn'); // 部门
        //var_dump(1111);die;
        //$tabName=$this->getTabName($exhibition_id);
        //$company_id = explode(',',$company_id);
        //$data=array();
        $res=$com->insert_com_dan($data, '', 'yuyue_member');
        if(!$res){
            return json(['code'=>0,'msg'=>'操作失败','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }

    /**
     * 删除公海
     */
    public function del(){
        $id = $this->request->param('id');
        if(empty($id)){
            return json(['code'=>0,'msg'=>'参数有误','data'=>'']);
        }
        $tabName='yuyue_member';
        $r = db($tabName)->where(['id'=>$id])->find();
        if(!$r){
            return json(['code'=>0,'msg'=>'记录不存在','data'=>'']);
        }
        $where=" id=".$id;
        $r = db($tabName)->where($where)->delete();
        if(!$r){
            return json(['code'=>0,'msg'=>'操作失败，请重试','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }
    /**
     * 批量删除公海
     */
    public function delall(){
//        $id = $this->request->param('id');
        $id = $this->request->param('project_id');
        $ids = explode(',',$id);
        if(empty($id)){
            return json(['code'=>0,'msg'=>'参数有误','data'=>'']);
        }
        foreach ($ids as $id){
            $r = $this->model->findWhere(['id'=>$id]);
            if(!$r){
                return json(['code'=>0,'msg'=>'id:'.$id.'记录不存在,批量删除失败','data'=>'']);
            }
            if($r['status']==2 || $r['status']==3){
                return json(['code'=>0,'msg'=>'id:'.$id.'记录已分配，批量删除失败','data'=>'']);
            }
        }

        Db::startTrans();
        try {
            $map['id'] = array('in',$ids);
            $r = $this->model->where($map)->delete();
//           $this->model->deleteWhere($map);
            Db::commit();
            return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
        } catch (\Exception $e) {
            //如获取到异常信息，对所有表的删、改、写操作，都会回滚至操作前的状态：
            Db::rollback();
            return json(['code'=>0,'msg'=>'操作失败，请重试','data'=>'']);
        }

    }


    /**
     * 分配业务员
     * 公海表 3 代表自提 4代表分配
     */
    public function give(){
        $public_id = $this->request->param('public_id');//公海id
        $data['sale_id'] = $this->admin['id'];//分配人id
        $data['member_id'] = $this->request->param('member_id');//业务员id
        $exhibition_id = $this->request->param('exhibition_id');//业务员id
        $data['update_time'] = time();
        $data['back'] = 3;
        #数据验证
        if(empty($public_id)){
            return json(['code'=>0,'msg'=>'公海数据有误']);
        }
        if(empty($exhibition_id)){
            return json(['code'=>0,'msg'=>'展会数据有误']);
        }
        if(empty($data['member_id'])){
            return json(['code'=>0,'msg'=>'业务员有误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        //先查询记录是否存在
        $where['id'] = array('in', $public_id);
        $where['member_id'] = array('neq',0);
        $res = db($tabName)->where($where)->select();
        if($res){
            return json(['code'=>0,'msg'=>'数据已被分配']);
        }
        $errorArr=array();
        $public_id = explode(',',$public_id);
        $is = true;
        foreach ($public_id as $v){
            $result=db($tabName)->where(['id'=>$v])->update($data);
            if(!$result){
                $is=false;
                array_push($errorArr,$v);
            }
        }
        if($is){
            return json(['code'=>1,'msg'=>'操作成功']);
        }else{
            $errIds= implode('，',$errorArr);
            return json(['code'=>0,'msg'=>$errIds.'展商未操作成功']);
        }
    }





    public function companyList_shaixuan()
    {
        //基础公司表
        //个人信息 中文姓名 职务 部门 手机 数据来源 所属洲 国家 省份 城市  公司中文名 地址 网址 固定电话 一级分类 二级分类
        //$keyword = $this->request->param('keyword');
       // var_dump(111);die;
        $page = $this->request->param('page');
        $where = array();
        $page = max(1, intval($page));
        $pagesize = 1;
        $where['is_delete'] = 0; //回头问下
        $exhibition_id = $this->request->param('exhibition_id');//展会id
        if(empty($exhibition_id)){
            return json(['code' => 0, 'msg' => '缺少关键主键展会id']);
        }
        // 查询 st 精确查询还是模糊 查询。。。。擦  都是必要的字段留着 其他的没卵用
        $name_cn = $this->request->param('name_cn'); //中文姓名
        $positions_cn = $this->request->param('positions_cn'); //职务
        $department_cn = $this->request->param('department_cn'); //职务
        $mobile = $this->request->param('mobile'); //手机
        $data_from = $this->request->param('data_from'); //数据来源
        $country = $this->request->param('country');//国家
        $province = $this->request->param('province');  //省份
        $area_city = $this->request->param('area_city');  //地级市
        $company_name = $this->request->param('company_name'); //公司中文名
        $tel = $this->request->param('tel');   //固定电话
        $link = $this->request->param('link'); //网址
        $category_id = $this->request->param('category_id');  //一级 分类
        $second_category_id = $this->request->param('second_category_id');     //二级 分类
        $parameter="is_delete=0";
        if(!empty($name_cn)){
            $where['name_cn'] = array('like', '%' . $name_cn . '%');
            $parameter.=" and name_cn like '%$name_cn%' ";
        }

        if(!empty($positions_cn)){
            $where['positions_cn'] = array('like', '%' . $positions_cn . '%');
            $parameter.=" and positions_cn like '%$positions_cn%' ";
        }

        if(!empty($department_cn)){
            $where['positions_cn'] = array('like', '%' . $department_cn . '%');
            $parameter.=" and department_cn like '%$department_cn%' ";
        }

        if(!empty($mobile)){
            $where['mobile'] = $mobile;
            $parameter.=" and mobile=$mobile";
        }

        if(!empty($data_from)){
            $where['data_from'] = array('like', '%' . $data_from . '%');
            $parameter.=" and data_from like '%$data_from%' ";
        }

        if(!empty($country)){
            $where['country'] = array('like', '%' . $country . '%');
            $parameter.=" and country like '%$country%' ";
        }

        if(!empty($province)){
            $where['province'] = array('like', '%' . $province . '%');
            $parameter.=" and province like '%$province%' ";
        }

        if(!empty($area_city)){
            $where['area_city'] = array('like', '%' . $area_city . '%');
            $parameter.=" and area_city like '%$area_city%' ";
        }

        if(!empty($company_name)){
            $where['company_name'] = array('like', '%' . $company_name . '%');
            $parameter.=" and company_name like '%$company_name%' ";
        }

        if(!empty($tel)){
            $where['tel'] = $tel;
            $parameter.=" and tel like=$tel";
        }

        if(!empty($link)){
            $where['tel'] = $link;
            $parameter.=" and tel=$link";
        }

        if(!empty($category_id)){
            $where['category_id'] = array('like', '%' . $category_id . '%');
            $parameter.=" and category_id like '%$category_id%' ";
        }

        if(!empty($second_category_id)){
            $where['second_category_id'] = array('like', '%' . $second_category_id . '%');
            $parameter.=" and second_category_id like '%$second_category_id%' ";
        }
        //$list =db('company')->field('id,company_name')->where($where)->order('id desc')->limit(($page-1)*$pagesize.','.$pagesize)->select();
       // $total=db('company')->where($where)->count();
        $w['exhibition_id'] = $exhibition_id;
        $newList=array();
 
        // 查询非公海 企业 0526
        $tabName=$this->getTabName($exhibition_id);
        $tabName='crm_'.$tabName;
        $sql2="select id,company_name from crm_company where ".$parameter." and id not in";
        $sql2.=" (select `company_id1` from ".$tabName.")";
        if($parameter == 'is_delete=0'){
            $sql2.=" limit ".($page-1)*$pagesize.",$pagesize";
        }
        $list1=Db::query($sql2);

        $sql21="select COUNT(*) as count1 from crm_company where ".$parameter." and id not in";
        $sql21.=" (select `company_id1` from ".$tabName.")";
        //$sql2.=" limit ".($page-1)*$pagesize.",$pagesize";
        $total=Db::query($sql21);


        $list=$list1;  //st
        $total=$total[0]['count1']; //st
        return json(['code' => 1, 'msg' => 'success', 'data' => ['list' => $list, 'total' => $total]]);
    }

    /**
     * 企业列表 公海数据比对筛选
     */
    public function companyListCompanysx(){
        $exhibition_id = input('exhibition_id');//展会id 
        $company_id = input('company_id');//,分割列表形式公司id
        $where['exhibition_id'] = $exhibition_id;
        if($company_id){
            $company_ids = explode(',',$company_id);
        }else{
            $company_ids =[];
        }
            //获取公海数据
        $listall = $this->model->field('company_id')->where($where)->select();
        $list =[];
        foreach($listall as $item){ 
            $list[]=$item['company_id'];
        }
        //排除公海有的数据
        $data = array_diff($company_ids,$list);//取差集
        if(!empty($data)){
            $uid_str=implode(",", array_merge($data));
            $pwhere['id'] = array('in', $uid_str);
            $res = model('Companymgr')->field('id,company_name')->where($pwhere)->select();
        }
        return json(['code' => 1, 'msg' => 'success', 'data' =>array_merge($data),'list'=>empty($res)?[]:$res]);
    }




    /**
     * 查看管理员
     *
     * @return void
     */
    public function index()
    {
        if (request()->isPost()) {
            $post = input('post.');
            $orgId = isset($post['org_id']) && $post['org_id'] != '' ? $post['org_id'] : 0;
            $pageSize = isset($post['pageSize']) && $post['pageSize'] != '' ? $post['pageSize'] : 10;
            $where['is_super'] = 0;
            if ($orgId != 0) {
                // $where['a.org_id'] = $orgId;
                $where[] = ['exp', Db::raw('FIND_IN_SET(' . $orgId . ',a.org_id_tree)')];
            }
            if (isset($post['keyword']) && $post['keyword'] != '') {
                $where['a.account|a.realname'] = ['like', '%' . $post['keyword'] . '%'];
            }
            $adminList = AdminModel::alias('a')
                ->with('role')
                ->join('crm_organization b', 'b.id = a.org_id', 'LEFT')
                ->where($where)
                ->field('a.id,a.account,a.realname,a.mobile,a.email,a.org_id,b.org_name,a.create_time,a.update_time')
                ->paginate($pageSize);
            $list = $adminList->toArray();
            unset($list['per_page'], $list['last_page']);
            return json(array('code' => '1', 'msg' => '成功', 'data' => $list));
        } else {
            return json(array('code' => '0', 'msg' => '请求失败'));
        }
    }



    // 查询下拉  获取所有列表 按照类别来
    public function selAll_xla_Bytype()
    {
        //==common
        $create_uid  = $this->admin['id'];
        // $id = $this->request->param('id');
        $type = $this->request->param('type');     //下拉属性

        //

        if (trim($type) == "gsxz") {
            // 公司性质
            $tbname = "xiala_gsxz"; // gtab

            $where = array('is_delete' => 0);
            // $where = "";
            $data = array('update_time' => time(), 'create_uid' => $create_uid);
        } elseif (trim($type) == "gsxt") {
            // 公司形态
            $tbname = "xiala_gsxt"; // gtab

            $where = array('is_delete' => 0);
            $data = array('update_time' => time(), 'create_uid' => $create_uid);
        }elseif (trim($type) == "gslevel") {
            // 公司级别
            $tbname = "xiala_gslevel";
            $where = array('is_delete' => 0);
            $data = array('update_time' => time(), 'create_uid' => $create_uid);
        }elseif (trim($type) == "sshy") {
            // 所属行业
            $tbname = "xiala_sshy";
            $where = array('is_delete' => 0);
            $data = array('update_time' => time(), 'create_uid' => $create_uid);
        }elseif (trim($type) == "ywxz") {
            // 业务性质
            $tbname = "xiala_ywxz";
            $where = array('is_delete' => 0);
            $data = array('update_time' => time(), 'create_uid' => $create_uid);
        }
        // var

        // ----------
        $list = model('Companyset')->selAll_common_xla($data, $where, $tbname);
        // var_dump ($r);die;
        if (!$list) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }

        return json(['code' => 1, 'msg' => 'success', 'data' => ['list' => $list]]);
        // return json(['code' => 1, 'msg' => '操作成功']);
    }




    /**
     * 基本信息修改
     * @return \think\response\Json|void
     */
    public function editCompany()
    {
        // com
        $id = $this->request->param('id'); //必须
        $create_uid  = $this->admin['id'];
        $selfcontent = $this->request->param('selfcontent'); //自定义表单 理论上只有新增 才有 。。让前台隐藏吧
        // com
        $company_name = $this->request->param('company_name'); //公司中文名
        $company_address = $this->request->param('company_address'); //公司地址
        $company_name_en = $this->request->param('company_name_en'); //    公司英文文名
        $company_describe = $this->request->param('company_describe'); //简介
        $tel = $this->request->param('tel');   //固定电话
        $link = $this->request->param('link');
        $product_brand = $this->request->param('product_brand');   //产品品牌
        $application_area = $this->request->param('application_area');    //应用领域  字段？？ 有两个
        $mobile = $this->request->param('mobile');
        $email = $this->request->param('email');
        $qq = $this->request->param('qq');
        $wechat = $this->request->param('wechat');
        $msn = $this->request->param('msn');
        $product_describe = $this->request->param('product_describe');   //产品介绍
        $product_positioning = $this->request->param('product_positioning');  //定位
        $product_keyword = $this->request->param('product_keyword');    //关键字
        //$application_area = $this->request->param('application_area');  //应用领域 下拉框？还是？？ 两个字段页面
        $remark = $this->request->param('remark');
        $category_id = $this->request->param('category_id');  //一级 分类
        $second_category_id = $this->request->param('second_category_id');     //二级 分类
        $product = $this->request->param('product');  //产品
        $capacitys = $this->request->param('capacitys');  //年产能
        $sale_fee = $this->request->param('sale_fee'); //年销售总额:
        $sale_pb = $this->request->param('sale_pb'); //pb年PB销售占比
        $pb_time = $this->request->param('pb_time');  //进入pb时间
        $pb_customer = $this->request->param('pb_customer'); //主要pb客户
        $country = $this->request->param('country');  //国家
        $country_code = $this->request->param('country_code'); //国家代码
        $area = $this->request->param('area'); //区域
        $province = $this->request->param('province');  //省份
        $area_city = $this->request->param('area_city');  //地级市
        $area_town = $this->request->param('area_town'); //县市
        // 个人信息
        $surname_cn = $this->request->param('surname_cn');  //中文 姓
        $surname_en = $this->request->param('surname_en');  //英文 姓
        $name_cn = $this->request->param('name_cn');     // 中文名
        $name_en = $this->request->param('name_en'); // 英文名
        $call_name_cn = $this->request->param('call_name_cn'); // 称谓 中
        $call_name_en = $this->request->param('call_name_en'); //称谓 英文
        $positions_cn = $this->request->param('positions_cn');  // 职务 中
        $positions_en = $this->request->param('positions_en'); //职务
        $department_cn = $this->request->param('department_cn'); // 部门中
        $department_en = $this->request->param('department_en'); //部门 英
        $tel_person_code = $this->request->param('tel_person_code');  // 区号
        $tel_person = $this->request->param('tel_person'); // 电话
        $tel_person_history = $this->request->param('tel_person_history'); //原始号码
        $mobile_person = $this->request->param('mobile_person'); //个人手机
        $fax_person = $this->request->param('fax_person');  // 传真
        $fax_history = $this->request->param('fax_history');  // 原始传真
        $email_person = $this->request->param('email_person');  // email 个人
        $mobile_status = $this->request->param('mobile_status');  // 电话已核对 是需要填写数字？？
        $addr_person = $this->request->param('addr_person');  // 地址 个人
        $info_level = $this->request->param('info_level'); // 信息质量
        $data_from = $this->request->param('data_from');  // 数据来源
        $duties = $this->request->param('duties');  // 岗位职责
        $job_nature = $this->request->param('job_nature');  // 工作性质
        $company_ID = $this->request->param('company_ID'); //公司id
        $persontype = $this->request->param('persontype'); //人员类别
        $industrys = $this->request->param('industrys'); // 行业
        $company_nature = $this->request->param('company_nature');  // 公司性质
        $qualifications = $this->request->param('qualifications');  // 资质
        $company_form = $this->request->param('company_form');  // 公司形态
        $business = $this->request->param('business');  // 业务性质
        $system_status = $this->request->param('system_status');  // 系统状态
        $id_card = $this->request->param('id_card');  // 证件号码
        $chau = $this->request->param('chau');  // 所属洲
        $ishzselfbrander = $this->request->param('ishzselfbrander');  // 是否合作过自有品牌客户
        $ishzselfbrand = $this->request->param('ishzselfbrand');  // 是否合作过自有品牌
        $exhibition_id =$this->request->param('exhibition_id');
        $bxid =$this->request->param('bxid');
        if(empty($exhibition_id) || empty($bxid)){
            return json(['code'=>0,'msg'=>'缺少关键字段','data'=>'']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $data = array(
            'create_uid' => $create_uid, 'update_time' => time(), 'selfcontent' => $selfcontent, 'remark' => $remark, 'company_name' => $company_name,
            'company_address'=>$company_address,'company_name_en' => $company_name_en, 'company_describe' => $company_describe, 'tel' => $tel, 'link' => $link,
            'product_brand' => $product_brand, 'application_area' => $application_area, 'mobile' => $mobile,
            'email' => $email, 'qq' => $qq, 'wechat' => $wechat, 'msn' => $msn, 'product_describe' => $product_describe,
            'product_positioning' => $product_positioning, 'product_keyword' => $product_keyword, 'remark' => $remark,
            'category_id' => $category_id, 'second_category_id' => $second_category_id, 'product' => $product,
            'capacitys' => $capacitys, 'sale_fee' => $sale_fee, 'sale_pb' => $sale_pb, 'pb_time' => $pb_time,
            'pb_customer' => $pb_customer, 'country' => $country, 'country_code' => $country_code, 'province' => $province,
            'area' => $area, 'area_city' => $area_city, 'area_town' => $area_town,
            'surname_cn' => $surname_cn, 'name_cn' => $name_cn, 'surname_en' => $surname_en,
            'name_en' => $name_en, 'call_name_cn' => $call_name_cn, 'call_name_en' => $call_name_en,
            'positions_cn' => $positions_cn, 'positions_en' => $positions_en, 'department_cn' => $department_cn,
            'department_en' => $department_en, 'tel_person_code' => $tel_person_code, 'tel_person' => $tel_person,
            'tel_person_history' => $tel_person_history, 'mobile_person' => $mobile_person, 'fax_person' => $fax_person,
            'fax_history' => $fax_history, 'email_person' => $email_person, 'mobile_status' => $mobile_status,
            'addr_person' => $addr_person, 'info_level' => $info_level, 'data_from' => $data_from,
            'duties' => $duties, 'job_nature' => $job_nature, 'company_ID' => $company_ID,
            'persontype' => $persontype, 'industrys' => $industrys, 'company_nature' => $company_nature, 'qualifications' => $qualifications,
            'company_form' => $company_form, 'business' => $business, 'system_status' => $system_status,
            'id_card' => $id_card, 'chau' => $chau, 'ishzselfbrander' => $ishzselfbrander, 'ishzselfbrand' => $ishzselfbrand,
        );
        if (empty($id)) {
            return json(['code' => 0, 'msg' => '参数有误，请核查']);
        }
        $where['id'] = $id;
        $where1['id'] = $bxid;
        $c_id =  $this->request->param('c_id');
        //事务开始
        Db::startTrans();
        try {
            //更新映射表
            $r = db($tabName)->where($where1)->    update($data);
            if(input('is_tb')==1){
                //同步基础公司库
                model('Companymgr')->where(['id'=>$c_id])->update($data);
            }
            Db::commit();
            return json(['code' => 1, 'msg' => '操作成功']);
        } catch (\Exception $e) {
            //如获取到异常信息，对所有表的删、改、写操作，都会回滚至操作前的状态：
            Db::rollback();
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }


//        if (!$r) {
//            return json(['code' => 0, 'msg' => '操作失败，请重试']);
//        }
//
//        return json(['code' => 1, 'msg' => '操作成功']);
    }

    /**
     * 参展历史
     * @return \think\response\Json|void
     */
    public function companyCzls(){
        $data = [];//参展历史数据查询
        return json(['code' => 1, 'msg' => 'success', 'data' => $data]);
    }


    /**
     * 进入公海后映射公司详情表
     * $id 公司id 公海id
     */
    private function tbCompany($id,$pid){
        //查询基础库里面是否有此基础数据备份了
        $public_company = db('company_public_company')->where(['c_id'=>$id,'public_id'=>$pid])->find();
        if( $public_company){
            //已经有值直接抛出
            return true;
        }
        Db::startTrans();
        try {
            $company = db('company')->where(['id'=>$id])->find();
            unset($company['id']);
            $data = $company;
            $data['c_id'] = $id;
            $data['public_id'] = $pid;
            db('company_public_company')->insert($data);
            Db::commit();
            return true;
        } catch (\Exception $e) {
            //如获取到异常信息，对所有表的删、改、写操作，都会回滚至操作前的状态：
            Db::rollback();
            return false;
        }
    }



}
